package org.senseframework.support.orm.mybatis.definition;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Author lanjian
 * Email  jianlan@iflytek.com
 */
public class EntityDefinition {




    public String table() {
        if (StringUtils.isBlank(tableAs)) {
            return table;
        }
        return table + " as " + tableAs;
    }

    public String joinTable() {
        if (StringUtils.isBlank(joinTable)) {
            throw new RuntimeException("join table is null");
        }
        return joinTable + " as " + joinTableAs;
    }

    public String on() {
        if (StringUtils.isBlank(tableOn) || StringUtils.isBlank(joinTableOn)) {
            throw new RuntimeException("on must not null");
        }
        return tableAs + "." + tableOn + "=" + joinTableAs + "." + joinTableOn;
    }

    private String id;

    private String table;

    private String tableAs;

    private JoinType joinType;

    private String joinTable;

    private String joinTableAs;

    private String tableOn;

    private String joinTableOn;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTableAs() {
        return tableAs;
    }

    public void setTableAs(String tableAs) {
        this.tableAs = tableAs;
    }

    public JoinType getJoinType() {
        return joinType;
    }

    public void setJoinType(JoinType joinType) {
        this.joinType = joinType;
    }

    public String getJoinTable() {
        return joinTable;
    }

    public void setJoinTable(String joinTable) {
        this.joinTable = joinTable;
    }

    public String getJoinTableAs() {
        return joinTableAs;
    }

    public void setJoinTableAs(String joinTableAs) {
        this.joinTableAs = joinTableAs;
    }

    public String getTableOn() {
        return tableOn;
    }

    public void setTableOn(String tableOn) {
        this.tableOn = tableOn;
    }

    public String getJoinTableOn() {
        return joinTableOn;
    }

    public void setJoinTableOn(String joinTableOn) {
        this.joinTableOn = joinTableOn;
    }

    private Map<String, EntityColumnDefinition> columnDefinitions = new HashMap<String, EntityColumnDefinition>();

    public void addEntityColumnDefinition(String p, EntityColumnDefinition entityColumnDefinition) {
        columnDefinitions.put(p, entityColumnDefinition);
    }

    public Map<String, EntityColumnDefinition> getColumnDefinitions() {
        return columnDefinitions;
    }

    public void setColumnDefinitions(Map<String, EntityColumnDefinition> columnDefinitions) {
        this.columnDefinitions = columnDefinitions;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }
}
